package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.YsDepartmentDTO;
import com.CST.entity.ys.YsDepartment;
import com.CST.service.ys.YsDepartmentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-04-20
 */
@Api(tags = "预算部门管理")
@RestController
@RequestMapping("/ysDepartment")
public class YsDepartmentController {

    private final YsDepartmentService service;

    public YsDepartmentController(YsDepartmentService service) {
        this.service = service;
    }

    @ApiOperation("分页查询")
    @PostMapping("/listYsDepartmentPage")
    public ResultObject<IPage<YsDepartment>> listYsDepartmentPage(@RequestBody YsDepartmentDTO dto) {
        return ResultObject.success(service.listYsDepartmentPage(dto));
    }

    @ApiOperation("查询")
    @PostMapping("/listYsDepartment")
    public ResultObject<List<YsDepartment>> listYsDepartment(String name, Integer status, Integer manageStatus) {
        return ResultObject.success(service.listYsDepartment(name,status,manageStatus));
    }

    @ApiOperation("查询资产类的部门")
    @PostMapping("/listYsManageAssetDepartment")
    public ResultObject<List<YsDepartment>> listYsManageAssetDepartment() {
        return ResultObject.success(service.listYsManageAssetDepartment());
    }

    @ApiOperation("部门添加下拉查询")
    @PostMapping("/listYsDepartmentCb")
    public ResultObject<List<YsDepartment>> listYsDepartmentCb(String name) {
        return ResultObject.success(service.listYsDepartmentCb(name));
    }

    @ApiOperation("保存或编辑")
    @PostMapping("/saveOrUpdateYsDepartment")
    public ResultObject<Boolean> saveOrUpdateYsDepartment(@RequestBody @Valid YsDepartment entity) {
        return ResultObject.success(service.saveOrUpdateYsDepartment(entity));
    }

    @ApiOperation("删除")
    @DeleteMapping("/removeYsDepartmentById")
    public ResultObject<Boolean> removeYsDepartmentById(@RequestParam Long id) {
        return ResultObject.success(service.removeYsDepartmentById(id));
    }

    @ApiOperation("导入")
    @PostMapping("/importExcelYsDepartment")
    public void importExcelYsDepartment(MultipartFile file) {
        service.importExcelYsDepartment(file);
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelYsDepartment")
    public void exportExcelYsDepartment(HttpServletResponse response) {
        service.exportExcelYsDepartment(response);
    }

    @ApiOperation("导出模板")
    @PostMapping("/exportExcelYsDepartmentDemo")
    public void exportExcelYsDepartmentDemo(HttpServletResponse response) {
        service.exportExcelYsDepartmentDemo(response);
    }
}
